import Conversation
import ConversationUI
import ConversationWindow
import UserMenu
import gtk
import PluginManagerDialog
import Controller

from AvatarHistory import *
from UserList import UserList
from emesenelib.ContactData import *

import UserPanel

import ContactManager

import UserMenu

import FileTransfer

import abstract.ContactManager as absContactManager

import emesenelib.ProfileManager as libProfileManager

import emesenelib.ContactData as libContactData

import emesenelib.core as libCore

import aspects

class Wrappers:
    def __init__(self, plugin, wrapperDebug=False):
        self.plugin = plugin
        
        self.wrapperDebug = wrapperDebug

        self.conversation = Conversation.Conversation

        self.pluginUnloading = PluginManagerDialog.PluginManagerDialog

        self.conversationUi = ConversationUI.ToolbarWidget
        self.inviteui = ConversationUI.InviteWindow
        self.conversationmenu = ConversationWindow.ConversationWindowMenu

        self.usermenu = UserMenu.UserMenu
        
        self.fileTransfer = FileTransfer.FileTransfer

        self.contactManager = ContactManager.ContactManager

        self.absContactManager = absContactManager.ContactManager

        self.libContactData = libContactData.ContactList

        self.profile = libProfileManager.ProfileManager

        self.userPanel = UserPanel.UserPanel

        self.userMenu = UserMenu.UserMenu
        
        self.controlOne = Controller.Controller
        
        self.libCore = libCore.Msnp

    def addWrappers(self):
        #Wrap for block and unblock - tests
        #aspects.with_wrap(self.plugin.plugin..userBlocked, self.profile.blockUser)
        #aspects.with_wrap(self.plugin.plugin..userUnblocked, self.profile.blockUser)#ContactList.unblockContact)

        #Wrap for conversations
        aspects.with_wrap(self.plugin.filterConversation, self.plugin.controller.conversationManager.newConversation)
        aspects.with_wrap(self.plugin.addingContact, self.plugin.controller.contacts.add)
        
        aspects.with_wrap(self.plugin.userJoin, self.conversation.userJoin)
        aspects.with_wrap(self.plugin.userLeave, self.conversation.userLeave)
        

        #Wrap for block and unblock - tests
        #aspects.with_wrap(self.plugin.preventBlock, self.plugin.controller.contacts.block)
        #aspects.with_wrap(self.plugin.preventUnblock, self.plugin.controller.contacts.unblock)

        #Wrap for images
        aspects.with_wrap(self.plugin.setUserPicture, self.plugin.controller.theme.getUserDisplayPicture)

        #wrap for Local Personal Stuff
        aspects.with_wrap(self.plugin.passportPuid, self.libCore.passportAuth)
        aspects.with_wrap(self.plugin.personalStatusChanged, self.controlOne.on_self_status_changed)
        aspects.with_wrap(self.plugin.personalNickChanged, self.userPanel.nickRefresh)
        aspects.with_wrap(self.plugin.personalMessageChanging, self.profile.updateUUX)
        aspects.with_wrap(self.plugin.personalAvatarChanging, self.plugin.controller.changeAvatar)

        #Wrap related to Contacts
        #__on_initial_status_changed, does not wrap... event the new aspects...
        #aspects.with_wrap(self.plugin.contactInitialStatus, ContactManager.ContactManager._on_initial_status_changed)
        aspects.with_wrap(self.plugin.contactNewAvatarChanging, self.controlOne.on_display_picture_changed)
        aspects.with_wrap(self.plugin.contactNickChanged, self.absContactManager._on_contact_nick_changed)
        aspects.with_wrap(self.plugin.contactPersonalMessage, self.libContactData.setContactPersonalMessage)
        aspects.with_wrap(self.plugin.contactStatusChanging, self.absContactManager._on_contact_status_changed)
        aspects.with_wrap(self.plugin.contactNewGroup, self.contactManager.move_to_group)
        aspects.with_wrap(self.plugin.contactBeeingRemoved, self.absContactManager._on_contact_removed)


        #Wrap for outgoing and ingoing messages
        aspects.with_wrap(self.plugin.logOutgoingMessage, self.plugin.controller.conversationManager.do_send_message)
        aspects.with_wrap(self.plugin.logIncomingMessage, self.plugin.controller.conversationManager.do_receive_message)

        #Wrap for file transfers
        aspects.with_wrap(self.plugin.fileTransfer, self.conversation.onFtInvite)
        aspects.with_wrap(self.plugin.fileSend, self.conversationUi.sendFileClicked)
        aspects.with_wrap(self.plugin.fileReceived, self.fileTransfer.onFtReceived)

        #Wrap to disable menus
        aspects.with_wrap(self.plugin.menuFileSend, self.conversationmenu.onSendFileActivate)
        aspects.with_wrap(self.plugin.preventEmail, self.usermenu.on_send_mail_activate)
        aspects.with_wrap(self.plugin.preventInvite, self.conversation.inviteUser)

        #Wrap to prevent unloading the plugin
        #aspects.with_wrap(self.plugin.preventPluginUnloading,  self.pluginUnloading.active_toggled)

        #aspects.with_wrap(self.plugin.preventUnloadPlugin, self.plugin.controller.pluginManager.stopPlugin)
        aspects.with_wrap(self.plugin.preventProfileView, self.userMenu.on_profile_activate)


    def removeWrappers(self):
        #Wrap for block and unblock - tests
        #aspects.without_wrap(self.plugin.userBlocked, self.profile.blockUser)
        #aspects.without_wrap(self.plugin.userUnblocked, self.profile.blockUser)#ContactList.unblockContact)

        #Wrap for conversations
        aspects.without_wrap(self.plugin.filterConversation, self.plugin.controller.conversationManager.newConversation)
        aspects.without_wrap(self.plugin.addingContact, self.plugin.controller.contacts.add)

        #Wrap for block and unblock - tests
        #aspects.without_wrap(self.plugin.preventBlock, self.plugin.controller.contacts.block)
        #aspects.without_wrap(self.plugin.preventUnblock, self.plugin.controller.contacts.unblock)

        #Wrap for images
        aspects.without_wrap(self.plugin.setUserPicture, self.plugin.controller.theme.getUserDisplayPicture)

        #wrap for Local Personal Stuff
        aspects.without_wrap(self.plugin.passportPuid, self.libCore.passportAuth)
        aspects.without_wrap(self.plugin.personalStatusChanged, self.controlOne.on_self_status_changed)
        aspects.without_wrap(self.plugin.personalNickChanged, self.userPanel.nickRefresh)
        aspects.without_wrap(self.plugin.personalMessageChanging, self.profile.updateUUX)
        aspects.without_wrap(self.plugin.personalAvatarChanging, self.plugin.controller.changeAvatar)


        #Wrap related to Contacts
        aspects.without_wrap(self.plugin.contactNewAvatarChanging, self.controlOne.on_display_picture_changed)
        aspects.without_wrap(self.plugin.contactNickChanged, self.absContactManager._on_contact_nick_changed)
        aspects.without_wrap(self.plugin.contactPersonalMessage, self.libContactData.setContactPersonalMessage)
        aspects.without_wrap(self.plugin.contactStatusChanging, self.absContactManager._on_contact_status_changed)
        aspects.without_wrap(self.plugin.contactNewGroup, self.contactManager.move_to_group)
        aspects.without_wrap(self.plugin.contactBeeingRemoved, self.absContactManager._on_contact_removed)


        #Wrap for outgoing and ingoing messages
        aspects.without_wrap(self.plugin.logOutgoingMessage, self.plugin.controller.conversationManager.do_send_message)
        aspects.without_wrap(self.plugin.logIncomingMessage, self.plugin.controller.conversationManager.do_receive_message)

        #Wrap for file transfers
        aspects.without_wrap(self.plugin.fileTransfer, self.conversation.onFtInvite)
        aspects.without_wrap(self.plugin.fileSend, self.conversationUi.sendFileClicked)
        aspects.without_wrap(self.plugin.fileReceived, self.fileTransfer.onFtReceived)

        #Wrap to disable menus
        aspects.without_wrap(self.plugin.menuFileSend, self.conversationmenu.onSendFileActivate)
        aspects.without_wrap(self.plugin.preventEmail, self.usermenu.on_send_mail_activate)
        aspects.without_wrap(self.plugin.preventInvite, self.conversation.inviteUser)

        #Wrap to prevent unloading the plugin
        #aspects.without_wrap(self.plugin.preventPluginUnloading,  self.pluginUnloading.active_toggled)

        #aspects.without_wrap(self.plugin.preventUnloadPlugin, self.plugin.controller.pluginManager.stopPlugin)
        aspects.without_wrap(self.plugin.preventProfileView, self.userMenu.on_profile_activate)
